//
//  ContractLookViewController.m
//  mcosApp
//
//  Created by YaSha_Tom on 2018/12/13.
//  Copyright © 2018年 YaSha-Tom. All rights reserved.
//

#import "ContractLookViewController.h"
#import "ContractInfoViewController.h"
#import "DataManager.h"
#import "ContractModel.h"

@interface ContractLookViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic,strong)UITableView *tableView;
@property (nonatomic,strong)NSArray *titleArray;
@property (nonatomic,copy)NSArray *dataSource;
@property (nonatomic,strong) NSMutableArray *contentArray;

@end

@implementation ContractLookViewController
- (NSMutableArray *)contentArray{
    if (!_contentArray) {
        _contentArray = [NSMutableArray array];
    }
    return _contentArray;
}
- (NSArray *)titleArray {
    if (!_titleArray) {
        _titleArray = @[@"商品名称",@"套餐面积(m²)", @"房产证面积(m²)",@"设计师",@"营销人员",@"合同总价",@"工期安排",@"乙方信息",@"甲方信息"];
    }
    return _titleArray;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"合同查看";
    self.view.backgroundColor = [UIColor whiteColor];
    [self initUI];
    [self doNetworking];
}
- (void)initUI {
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kSCREEN_WIDTH, kSCREEN_HEIGHT-kTopHeight) style:UITableViewStyleGrouped];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.view addSubview:self.tableView];
}
- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.titleArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (cell == nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
    }
    cell.selectionStyle=UITableViewCellSelectionStyleNone;//取消cell 的点击效果
    cell.textLabel.text = self.self.titleArray[indexPath.row];
    if (self.contentArray.count > 0) {
        if (indexPath.row <=5) {
            cell.detailTextLabel.text = self.contentArray[indexPath.row];
            cell.accessoryType =  UITableViewCellAccessoryNone; //显示最右边的箭头
        }else{
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; //显示最右边的箭头
        }
    }
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 6) {
        ContractInfoViewController *contractInfoViewController = [[ContractInfoViewController alloc]init];
        contractInfoViewController.titleStr = @"乙方信息";
        [self.navigationController pushViewController:contractInfoViewController animated:YES];
    }else if (indexPath.row == 7){
        ContractInfoViewController *contractInfoViewController = [[ContractInfoViewController alloc]init];
        contractInfoViewController.titleStr = @"甲方信息";
        [self.navigationController pushViewController:contractInfoViewController animated:YES];
    }
}
- (void)doNetworking{
    NSString *urlString = [NSString stringWithFormat:@"%@%@",Domain,getContractInfo];
    NSDictionary *dic = @{@"contractId":self.id};
    [YSNetManager ys_request_GETWithUrlString:urlString isNeedCache:NO parameters:dic successBlock:^(id response) {
        NSLog(@"成功%@",response);
        if ([response[@"code"]  isEqual: @1]) {
            self.dataSource = [DataManager getContractLookData:response];
           [self dataProcessing];
        }else{
            [QMUITips showSucceed:response[@"msg"] inView:self.view hideAfterDelay:1];
        }
    } failureBlock:^(NSError *error) {
        NSLog(@"失败%@",error);
    } progress:nil];
}

- (void)dataProcessing {
    ContractModel *model = self.dataSource[0];
    [self.contentArray addObject:model.wareName];
    [self.contentArray addObject:[NSString stringWithFormat:@"%@",model.sgArea]];
    [self.contentArray addObject:[NSString stringWithFormat:@"%@",model.buildArea]];
    [self.contentArray addObject:model.designerName];
    [self.contentArray addObject:model.marketerName];
    [self.contentArray addObject:[NSString stringWithFormat:@"¥%@",model.contrMoney]];
    [self.contentArray addObject:[NSString stringWithFormat:@"%@－%@",model.contrStartDate,model.contrCompletDate]];
    [self.tableView reloadData];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
